﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Playbook.Core
{
    /// <summary>
    /// Represents the application.
    /// </summary>
    public static class Shell
    {
        public static event EventHandler<EventArguments.LogEventArgs> OnLogged;

        /// <summary>
        /// Sets up the shell
        /// </summary>
        public static void Initialize()
        {
            Shell.Session = new SessionContext();

            string url = System.Configuration.ConfigurationManager.AppSettings["DataServicesURL"];

            if (string.IsNullOrWhiteSpace(url))
            {
                throw new Exception("DataServicesURL must be in AppSettings!");
            }
            else
            {
                Shell.DataServicesURI = new Uri(url);
            }

        }

        /// <summary>
        /// Web address of the Playbook data services OData provider.
        /// </summary>
        public static Uri DataServicesURI { get; private set; }

        public static void Log(object sender, string message)
        {
            if (OnLogged != null)
            {
                OnLogged(sender, new EventArguments.LogEventArgs(message));
            }
        }

        public static void Shutdown()
        {
        }

        /// <summary>
        /// User Agent
        /// </summary>
        public static string UserAgent
        {
            get
            {
                return string.Format("Playbook 1/{0}", Version.ToString());
            }
        }

        /// <summary>
        /// License key of the application.
        /// </summary>
        public static string LicenseKey { get; set; }

        /// <summary>
        /// Name of the application
        /// </summary>
        public static string Name { get; set; }

        /// <summary>
        /// Location of the application's logo.
        /// </summary>
        public static string LogoImageURL { get; set; }

        /// <summary>
        /// Location for application support.
        /// </summary>
        public static string SupportURL { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public static DateTime CreateDate { get; set; }

        public static SessionContext Session { get; set; }

        /// <summary>
        /// The version of this assembly.
        /// </summary>
        public static Version Version
        {
            get { return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; }
        }

    }
}
